package geom

type Point struct {
	X, Y float64
}

func (p Point) MinDistanceTo(positions []Point) float64 {
	if len(positions) == 0 {
		return 0
	}
	v := p.AsVec2()
	dist := positions[0].AsVec2().Sub(v).Length()
	for _, x := range positions[1:] {
		d := x.AsVec2().Sub(v).Length()
		if d < dist {
			dist = d
		}
	}
	return dist
}

func (p Point) AsVec2() Vec2 {
	return Vec2{p.X, p.Y}
}

func (p Point) ToIntPoint() IntPoint {
	return IntPoint{X: int(p.X), Y: int(p.Y)}
}

func (p Point) DistanceTo(point Point) float64 {
	return p.AsVec2().Sub(point.AsVec2()).Length()
}

func (p Point) AngleTo(p2 Point) Radian {
	return p2.AsVec2().Sub(p.AsVec2()).ToRadian()
}

type IntPoint struct {
	X, Y int
}

func (p IntPoint) AsPoint() Point {
	return Point{X: float64(p.X), Y: float64(p.Y)}
}

type DirectionPosition struct {
	Vec2
	Angle Radian
}

func NewDPos(x, y float64, a Radian) DirectionPosition {
	return DirectionPosition{Vec2{X: x, Y: y}, a}
}
